<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加经纬度</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <#assign base=request.contextPath  />
    <link rel="stylesheet" href="${base}/frame/layui/css/layui.css?t=1534970980648" media="all">
    <script type="text/javascript" src="${base}/js/zhang.js"></script>
    <script src="${base}/frame/layui/layui.all.js" charset="utf-8"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery-1.4.4.min.js"></script>
    <script src="${base}/js/jquery.min.js"></script>
    <script type="text/javascript" src="${base}/wangEdit/wangEditor.min.js"></script>
    <style type="text/css">
        form {
            padding: 20px;
        }

        .layui-btn-radius {
            border-radius: 5px;
        }

        .layui-table-cell {
            height: auto;
            white-space: normal;
        }
    </style>
</head>
<body>
<form class="layui-form" action="">
    <input type="hidden" id="id" />
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">站点名称</label>
            <div class="layui-input-inline">
                <input name="name" id="name" lay-verify="required" autocomplete="off" class="layui-input "
                       type="text">
            </div>

        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">站点地址</label>
            <div class="layui-input-inline">
                <input name="address" id="address" lay-verify="required" autocomplete="off" class="layui-input "
                       type="text">
            </div>

        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">所属品牌</label>
            <div class="layui-input-inline">
                <input name="brand" id="brand" lay-verify="required" autocomplete="off" class="layui-input "
                       type="text">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">经维度</label>
        <div class="layui-input-inline">
            <input type="text" onclick="showMap()" id="latlng" name="title" lay-verify="required" autocomplete="off" placeholder="请选择坐标" class="layui-input">
            <input type="hidden" id="lat"  >
            <input type="hidden"   id="lng"  >
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">优惠信息</label>
            <div class="layui-input-inline">
                <input name="discount" id="discount" lay-verify="required" autocomplete="off" class="layui-input "
                       type="text">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-upload">
            <button type="button" class="layui-btn" id="test2">站点图片</button>
            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                预览图：
                <div id="urlList">
                    <#list url as url>
                        <img src="${url.url}" style="width: 100px;height: 100px;">
                    </#list>
                </div>
                <div class="layui-upload-list" id="demo2"></div>
            </blockquote>
        </div>
    </div>


    <div class="layui-form-item" style="text-align:center">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-radius" lay-submit lay-filter="formDemo" type="button" id="aa"
                    onclick="onSubmit()" style="background-color: #0092EF;">立即提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-radius">重置</button>
        </div>
    </div>
</form>
<script>
    var urlList = [];
    layui.use(['form', 'layedit', 'laydate', 'layer','upload'], function () {
        var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , upload = layui.upload
                , laydate = layui.laydate;



        //多图片上传
        upload.render({
            elem: '#test2'
            ,url: '${base}/admin/file/upload'
            ,multiple: true
            ,before: function(obj){
                layer.load(1); //风格1的加载
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#urlList').remove();
                    $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img" style="width:100px;height:100px;">')
                });
            }
            ,done: function(res){
                layer.closeAll('loading');
                //上传完毕
                urlList.push(res.data)

            }
        });

    })
</script>
<script>


    //添加
    function onSubmit() {

        if($("#name").val()==""){
            layer.msg("站点名称不能为空")
            return;
        }
        if($("#address").val()==""){
            layer.msg("站点地址不能为空")
            return;
        }
        if($("#brand").val()==""){
            layer.msg("站点品牌不能为空")
            return;
        }

        var jsonData = {};

        jsonData.longitude=$("#lng").val();
        jsonData.dimension=$("#lat").val();
        jsonData.name=$("#name").val();
        jsonData.address=$("#address").val();
        jsonData.brand=$("#brand").val();
        jsonData.discount=$("#discount").val();
        jsonData.pids = urlList;
        jsonData.id=$("#id").val();
        $.ajax({
            type: "POST",
            contentType: "application/json;charset=UTF-8",
            url: "${base}/admin/site/updateByIdSite",
            data: JSON.stringify(jsonData),
            success: function (data) {
                if(data.code===200){
                    layer.msg(data.msg);
                    setTimeout(function () {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    }, 300)
                    var table = parent.layui.table;
                    //表刷新方法
                    table.reload('testReload', {
                        url: '${base}/admin/site/selectMyPage'
                        , where: {} //设定异步数据接口的额外参数
                        //,height: 300
                    });
                }else{
                    layer.msg(data.msg)
                }

            }
        });
    }

    //弹出层
    function showMap(){
        layer.open({
            title:"鼠标点击获取经纬度",
            type: 2,
            anim: 2,
            maxmin: true,
            content: "${base}/admin/site/charg_map" ,//这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
            area: ['100%', '100%']
        });

    }
</script>

</body>
</html>
